<!DOCTYPE html>
<html lang="cn">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css">
        #nav li{
            width: 300px;
            line-height: 40px;
            border: 1px solid #000;
        }
    </style>
</head>
<body>
    <h1>JS 事件</h1>
    <hr>

    <ul id="nav">
        <li>小静静, 你宣我吗? 宣1</li>
        <li>小舒舒, 你宣我吗? 宣2</li>
        <li>小飞飞, 你宣我吗? 宣3</li>
        <li>小撸撸, 你宣我吗? 宣4</li>
        <li>小翠翠, 你宣我吗? 宣5</li>
    </ul>

    <hr>
    <div id="btnlist">
        <button>获取第1句话</button>
        <button>获取第2句话</button>
        <button>获取第3句话</button>
        <button>获取第4句话</button>
        <button>获取第5句话</button>
    </div>

    <script>
	    var lis = document.getElementById('nav').getElementsByTagName('li');
	    var btns = document.getElementById('btnlist').getElementsByTagName('button');
	    // console.log(btns);
	    
	    for (var i = 0; i < btns.length; i++) {
	        (function (i){
	            btns[i].onclick = function() {
	                // alert(this.innerHTML);
	                // console.log(i);
	                alert(lis[i].innerHTML);
	            }
	        })(i);
	    }
    </script>
</body>
</html>